﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

namespace SecondClassAssignment{
    public partial class LoginWindow : Form{
        
        private readonly Bank _bank;
        private BalanceWindow _balanceWindow;
        

        private void Confirm_Click(object sender, EventArgs e){
            var idStr = id.Text.Trim();
            var pwdStr = pwd.Text.Trim();

            Account account = _bank.IsLegal(new Account(idStr, pwdStr));
            
            if (account != null) {
                id.BackColor = Color.Chartreuse;
                Hide();
                _balanceWindow = new BalanceWindow(account);
                _balanceWindow.Show();
            }
            else
                mistakeInfo.Text = "账号或密码错误";
        }

        private void ClearMistake(object sender, EventArgs e){
            mistakeInfo.Text = "";
        }
        
        public LoginWindow(){
            InitializeComponent();
            _bank = new Bank();
            _bank.Add(new Account("admin", "admin", 0));
            confirm.Click += Confirm_Click;
            id.TextChanged += ClearMistake;
            pwd.TextChanged += ClearMistake;
        }
    }
}